#include <iostream>

using namespace std;
const int N = 1e5 + 10;
int pos;
struct node{
	string s;
	int num;
}a[N];
string s[N];
int n;

int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> s[i];	
	}
	string t = s[1];
	int num = 1;
	for(int i = 2; i <= n + 1; i++)
	{
		if(s[i] != t)
		{
			a[++pos].num = num;
			a[pos].s = t;
			t = s[i];
			num = 1;
		}
		else 
		{
			num++;
		}
	}
//	for(int i = 1; i <= pos; i++) cout << a[i].s  << " " << a[i].num << endl;
	int ret = 1;
	for(int i = 1; i <= pos; i++)
	{
		if(a[i].num != 1) ret = max(ret, a[i].num);
		else
		{
			if(a[i - 1].s == a[i + 1].s)
			{
				ret = max(ret, a[i - 1].num + a[i + 1].num);
			}
		}
	}
	cout << ret << endl;
	return 0;
}
